package Pages;

import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class LoginPage extends Page {
    public LoginPage(WebDriver driver) {
       super(driver);
    }

    public ProductBacklogPage correctLogin() {
        provideLoginCredentials("admin", "password");
        return new ProductBacklogPage(driver);
    }

    public LoginPage open() {
        driver.get("http://szkolenia.bananascrum.com");
        return this;
    }



    public LoginPage tryLogin(String login, String password) {
        provideLoginCredentials(login, password);
        return this;
    }

    protected void provideLoginCredentials(String login, String password) {
        typeText(By.id("login"), login);
        typeText(By.id("password"), password);
        click(By.name("commit"));
    }

    public void assertThatUserIsNotLoggedIn() {
        Assert.assertEquals("Login failed", driver.findElement(By.id("flash")).getText());
    }
}
